import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class Demo2 {
    public static void main(String[] args) {
        BlockingQueue<Integer> queue =new LinkedBlockingQueue<>(1000);
        Thread producer =new Thread(()->{
              try {
                  int n=0;
                  while (true) {
                      queue.put(n);
                      Thread.sleep(1000);
                      System.out.println("生产者生产："+n++);
                  }
              } catch (InterruptedException e) {
                  throw new RuntimeException(e);
              }
        });
        Thread customers =new Thread(()->{
            try {
                while (true) {
                    System.out.println("消费者取出："+queue.take());
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        producer.start();
        customers.start();
    }
}
